package classes;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.ContentHandler;

public class ConfigJavaParser{

	private  XMLReader parser;
	private  String uri;// = "Config.xml";
	private  ArrayList<Agent> list = new ArrayList<Agent>();
	private  ContentHandler CH; 
		
	public ConfigJavaParser(String uri)
	{
		this.uri = uri;
		parser = new SAXParser();
	}
	
	public ArrayList<Agent> getConfig()
	{
		System.out.println("Parsing file: "+uri);
		CH = new ConfigTextExtractor(list);
		
		try 
		{
			parser.setContentHandler(CH);
			FileInputStream input = new FileInputStream(uri);
			parser.parse(new InputSource(input));
		} 
		catch (IOException e) 
		{e.printStackTrace();} 
		catch (SAXException e) 
		{e.printStackTrace();}
		for(Agent a : list)
			System.out.println(a.toString());
		return list;
	}
	
	
	
	
	
	
}
